
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.transition_state &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.transition_state</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.transition_state</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Some reimplementation of Henkelman&#39;s Transition State Analysis utilities,</span>
<span class="sd">which are originally in Perl. Additional features beyond those offered by</span>
<span class="sd">Henkelman&#39;s utilities will be added.</span>

<span class="sd">This allows the usage and customization in Python.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">glob</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">jsanitize</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>

<span class="kn">from</span> <span class="nn">pymatgen.util.plotting</span> <span class="kn">import</span> <span class="n">pretty_plot</span>
<span class="kn">from</span> <span class="nn">pymatgen.io.vasp</span> <span class="kn">import</span> <span class="n">Poscar</span><span class="p">,</span> <span class="n">Outcar</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.structure_matcher</span> <span class="kn">import</span> <span class="n">StructureMatcher</span>
<span class="n">scipy_old_piecewisepolynomial</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="kn">import</span> <span class="n">PiecewisePolynomial</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="kn">import</span> <span class="n">CubicSpline</span>

    <span class="n">scipy_old_piecewisepolynomial</span> <span class="o">=</span> <span class="kc">False</span>


<span class="n">__author__</span> <span class="o">=</span> <span class="s1">&#39;Shyue Ping Ong&#39;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s1">&#39;Copyright 2013, The Materials Virtual Lab&#39;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s1">&#39;0.1&#39;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s1">&#39;Shyue Ping Ong&#39;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s1">&#39;ongsp@ucsd.edu&#39;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s1">&#39;6/1/15&#39;</span>


<div class="viewcode-block" id="NEBAnalysis"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis">[docs]</a><span class="k">class</span> <span class="nc">NEBAnalysis</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    An NEBAnalysis class.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">forces</span><span class="p">,</span> <span class="n">structures</span><span class="p">,</span> <span class="n">spline_options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes an NEBAnalysis from the cumulative root mean squared distances</span>
<span class="sd">        between structures, the energies, the forces, the structures and the</span>
<span class="sd">        interpolation_order for the analysis.</span>

<span class="sd">        Args:</span>
<span class="sd">            r: Root mean square distances between structures</span>
<span class="sd">            energies: Energies of each structure along reaction coordinate</span>
<span class="sd">            forces: Tangent forces along the reaction coordinate.</span>
<span class="sd">            structures ([Structure]): List of Structures along reaction</span>
<span class="sd">                coordinate.</span>
<span class="sd">            spline_options (dict): Options for cubic spline. For example,</span>
<span class="sd">                {&quot;saddle_point&quot;: &quot;zero_slope&quot;} forces the slope at the saddle to</span>
<span class="sd">                be zero.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">r</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">energies</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">forces</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forces</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structures</span> <span class="o">=</span> <span class="n">structures</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spline_options</span> <span class="o">=</span> <span class="n">spline_options</span> <span class="k">if</span> <span class="n">spline_options</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> \
            <span class="k">else</span> <span class="p">{}</span>

        <span class="c1"># We do a piecewise interpolation between the points. Each spline (</span>
        <span class="c1"># cubic by default) is constrained by the boundary conditions of the</span>
        <span class="c1"># energies and the tangent force, i.e., the derivative of</span>
        <span class="c1"># the energy at each pair of points.</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">setup_spline</span><span class="p">(</span><span class="n">spline_options</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">spline_options</span><span class="p">)</span>

<div class="viewcode-block" id="NEBAnalysis.setup_spline"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis.setup_spline">[docs]</a>    <span class="k">def</span> <span class="nf">setup_spline</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spline_options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Setup of the options for the spline interpolation</span>

<span class="sd">        Args:</span>
<span class="sd">            spline_options (dict): Options for cubic spline. For example,</span>
<span class="sd">                {&quot;saddle_point&quot;: &quot;zero_slope&quot;} forces the slope at the saddle to</span>
<span class="sd">                be zero.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">spline_options</span> <span class="o">=</span> <span class="n">spline_options</span>
        <span class="n">relative_energies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">scipy_old_piecewisepolynomial</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">spline_options</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Option for saddle point not available with&#39;</span>
                                   <span class="s1">&#39;old scipy implementation&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">spline</span> <span class="o">=</span> <span class="n">PiecewisePolynomial</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">relative_energies</span><span class="p">,</span> <span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">forces</span><span class="p">])</span><span class="o">.</span><span class="n">T</span><span class="p">,</span>
                <span class="n">orders</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># New scipy implementation for scipy &gt; 0.18.0</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">spline_options</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;saddle_point&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;zero_slope&#39;</span><span class="p">:</span>
                <span class="n">imax</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">relative_energies</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">spline</span> <span class="o">=</span> <span class="n">CubicSpline</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">[:</span><span class="n">imax</span> <span class="o">+</span> <span class="mi">1</span><span class="p">],</span>
                                          <span class="n">y</span><span class="o">=</span><span class="n">relative_energies</span><span class="p">[:</span><span class="n">imax</span> <span class="o">+</span> <span class="mi">1</span><span class="p">],</span>
                                          <span class="n">bc_type</span><span class="o">=</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)))</span>
                <span class="n">cspline2</span> <span class="o">=</span> <span class="n">CubicSpline</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">[</span><span class="n">imax</span><span class="p">:],</span> <span class="n">y</span><span class="o">=</span><span class="n">relative_energies</span><span class="p">[</span><span class="n">imax</span><span class="p">:],</span>
                                       <span class="n">bc_type</span><span class="o">=</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">spline</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">c</span><span class="o">=</span><span class="n">cspline2</span><span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">cspline2</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">spline</span> <span class="o">=</span> <span class="n">CubicSpline</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">relative_energies</span><span class="p">,</span>
                                          <span class="n">bc_type</span><span class="o">=</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)))</span></div>

<div class="viewcode-block" id="NEBAnalysis.from_outcars"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis.from_outcars">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_outcars</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">outcars</span><span class="p">,</span> <span class="n">structures</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes an NEBAnalysis from Outcar and Structure objects. Use</span>
<span class="sd">        the static constructors, e.g., :class:`from_dir` instead if you</span>
<span class="sd">        prefer to have these automatically generated from a directory of NEB</span>
<span class="sd">        calculations.</span>

<span class="sd">        Args:</span>
<span class="sd">            outcars ([Outcar]): List of Outcar objects. Note that these have</span>
<span class="sd">                to be ordered from start to end along reaction coordinates.</span>
<span class="sd">            structures ([Structure]): List of Structures along reaction</span>
<span class="sd">                coordinate. Must be same length as outcar.</span>
<span class="sd">            interpolation_order (int): Order of polynomial to use to</span>
<span class="sd">                interpolate between images. Same format as order parameter in</span>
<span class="sd">                scipy.interplotate.PiecewisePolynomial.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">outcars</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">structures</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;# of Outcars must be same as # of Structures&quot;</span><span class="p">)</span>

        <span class="c1"># Calculate cumulative root mean square distance between structures,</span>
        <span class="c1"># which serves as the reaction coordinate. Note that these are</span>
        <span class="c1"># calculated from the final relaxed structures as the coordinates may</span>
        <span class="c1"># have changed from the initial interpolation.</span>
        <span class="n">r</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">prev</span> <span class="o">=</span> <span class="n">structures</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">st</span> <span class="ow">in</span> <span class="n">structures</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
            <span class="n">dists</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">s2</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="n">s1</span><span class="p">)</span> <span class="k">for</span> <span class="n">s1</span><span class="p">,</span> <span class="n">s2</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">prev</span><span class="p">,</span> <span class="n">st</span><span class="p">)])</span>
            <span class="n">r</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">dists</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)))</span>
            <span class="n">prev</span> <span class="o">=</span> <span class="n">st</span>
        <span class="n">r</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cumsum</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>

        <span class="n">energies</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">forces</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">outcars</span><span class="p">):</span>
            <span class="n">o</span><span class="o">.</span><span class="n">read_neb</span><span class="p">()</span>
            <span class="n">energies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">outcars</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]:</span>
                <span class="n">forces</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">forces</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;tangent_force&quot;</span><span class="p">])</span>
        <span class="n">forces</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forces</span><span class="p">)</span>
        <span class="n">r</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">r</span><span class="o">=</span><span class="n">r</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="n">energies</span><span class="p">,</span> <span class="n">forces</span><span class="o">=</span><span class="n">forces</span><span class="p">,</span>
                   <span class="n">structures</span><span class="o">=</span><span class="n">structures</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>

<div class="viewcode-block" id="NEBAnalysis.get_extrema"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis.get_extrema">[docs]</a>    <span class="k">def</span> <span class="nf">get_extrema</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">normalize_rxn_coordinate</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the positions of the extrema along the MEP. Both local</span>
<span class="sd">        minimums and maximums are returned.</span>

<span class="sd">        Args:</span>
<span class="sd">            normalize_rxn_coordinate (bool): Whether to normalize the</span>
<span class="sd">                reaction coordinate to between 0 and 1. Defaults to True.</span>

<span class="sd">        Returns:</span>
<span class="sd">            (min_extrema, max_extrema), where the extrema are given as</span>
<span class="sd">            [(x1, y1), (x2, y2), ...].</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">),</span> <span class="mf">0.01</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spline</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span>

        <span class="n">scale</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">normalize_rxn_coordinate</span> <span class="k">else</span> <span class="mi">1</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">min_extrema</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">max_extrema</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]:</span>
                <span class="n">min_extrema</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">scale</span><span class="p">,</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
            <span class="k">elif</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]:</span>
                <span class="n">max_extrema</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">scale</span><span class="p">,</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">return</span> <span class="n">min_extrema</span><span class="p">,</span> <span class="n">max_extrema</span></div>

<div class="viewcode-block" id="NEBAnalysis.get_plot"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis.get_plot">[docs]</a>    <span class="k">def</span> <span class="nf">get_plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">normalize_rxn_coordinate</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">label_barrier</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the NEB plot. Uses Henkelman&#39;s approach of spline fitting</span>
<span class="sd">        each section of the reaction path based on tangent force and energies.</span>

<span class="sd">        Args:</span>
<span class="sd">            normalize_rxn_coordinate (bool): Whether to normalize the</span>
<span class="sd">                reaction coordinate to between 0 and 1. Defaults to True.</span>
<span class="sd">            label_barrier (bool): Whether to label the maximum barrier.</span>

<span class="sd">        Returns:</span>
<span class="sd">            matplotlib.pyplot object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">plt</span> <span class="o">=</span> <span class="n">pretty_plot</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">normalize_rxn_coordinate</span> <span class="k">else</span> <span class="mi">1</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">),</span> <span class="mf">0.01</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">spline</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span>
        <span class="n">relative_energies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span> <span class="o">*</span> <span class="n">scale</span><span class="p">,</span> <span class="n">relative_energies</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">,</span> <span class="s1">&#39;ro&#39;</span><span class="p">,</span>
                 <span class="n">x</span> <span class="o">*</span> <span class="n">scale</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;k-&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s2">&quot;Reaction coordinate&quot;</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s2">&quot;Energy (meV)&quot;</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">ylim</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">-</span> <span class="mi">10</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">*</span> <span class="mf">1.02</span> <span class="o">+</span> <span class="mi">20</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">label_barrier</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="n">x</span> <span class="o">*</span> <span class="n">scale</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
            <span class="n">barrier</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">d</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="n">barrier</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="p">[</span><span class="n">barrier</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">barrier</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span> <span class="s1">&#39;k--&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%.0f</span><span class="s1"> meV&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">y</span><span class="p">)),</span>
                         <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="n">barrier</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">barrier</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">1.02</span><span class="p">),</span>
                         <span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="n">barrier</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">barrier</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">1.02</span><span class="p">),</span>
                         <span class="n">horizontalalignment</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">plt</span></div>

<div class="viewcode-block" id="NEBAnalysis.from_dir"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis.from_dir">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dir</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">root_dir</span><span class="p">,</span> <span class="n">relaxation_dirs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes a NEBAnalysis object from a directory of a NEB run.</span>
<span class="sd">        Note that OUTCARs must be present in all image directories. For the</span>
<span class="sd">        terminal OUTCARs from relaxation calculations, you can specify the</span>
<span class="sd">        locations using relaxation_dir. If these are not specified, the code</span>
<span class="sd">        will attempt to look for the OUTCARs in 00 and 0n directories,</span>
<span class="sd">        followed by subdirs &quot;start&quot;, &quot;end&quot; or &quot;initial&quot;, &quot;final&quot; in the</span>
<span class="sd">        root_dir. These are just some typical conventions used</span>
<span class="sd">        preferentially in Shyue Ping&#39;s MAVRL research group. For the</span>
<span class="sd">        non-terminal points, the CONTCAR is read to obtain structures. For</span>
<span class="sd">        terminal points, the POSCAR is used. The image directories are</span>
<span class="sd">        assumed to be the only directories that can be resolved to integers.</span>
<span class="sd">        E.g., &quot;00&quot;, &quot;01&quot;, &quot;02&quot;, &quot;03&quot;, &quot;04&quot;, &quot;05&quot;, &quot;06&quot;. The minimum</span>
<span class="sd">        sub-directory structure that can be parsed is of the following form (</span>
<span class="sd">        a 5-image example is shown):</span>

<span class="sd">        00:</span>
<span class="sd">        - POSCAR</span>
<span class="sd">        - OUTCAR</span>
<span class="sd">        01, 02, 03, 04, 05:</span>
<span class="sd">        - CONTCAR</span>
<span class="sd">        - OUTCAR</span>
<span class="sd">        06:</span>
<span class="sd">        - POSCAR</span>
<span class="sd">        - OUTCAR</span>

<span class="sd">        Args:</span>
<span class="sd">            root_dir (str): Path to the root directory of the NEB calculation.</span>
<span class="sd">            relaxation_dirs (tuple): This specifies the starting and ending</span>
<span class="sd">                relaxation directories from which the OUTCARs are read for the</span>
<span class="sd">                terminal points for the energies.</span>

<span class="sd">        Returns:</span>
<span class="sd">            NEBAnalysis object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">neb_dirs</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">root_dir</span><span class="p">):</span>
            <span class="n">pth</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">pth</span><span class="p">)</span> <span class="ow">and</span> <span class="n">d</span><span class="o">.</span><span class="n">isdigit</span><span class="p">():</span>
                <span class="n">i</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
                <span class="n">neb_dirs</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">pth</span><span class="p">))</span>
        <span class="n">neb_dirs</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">neb_dirs</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">d</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="n">outcars</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">structures</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Setup the search sequence for the OUTCARs for the terminal</span>
        <span class="c1"># directories.</span>
        <span class="n">terminal_dirs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">relaxation_dirs</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">terminal_dirs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">relaxation_dirs</span><span class="p">)</span>
        <span class="n">terminal_dirs</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">neb_dirs</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">neb_dirs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]))</span>
        <span class="n">terminal_dirs</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
                              <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;start&quot;</span><span class="p">,</span> <span class="s2">&quot;end&quot;</span><span class="p">]])</span>
        <span class="n">terminal_dirs</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
                              <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;initial&quot;</span><span class="p">,</span> <span class="s2">&quot;final&quot;</span><span class="p">]])</span>

        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">neb_dirs</span><span class="p">:</span>
            <span class="n">outcar</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="s2">&quot;OUTCAR*&quot;</span><span class="p">))</span>
            <span class="n">contcar</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="s2">&quot;CONTCAR*&quot;</span><span class="p">))</span>
            <span class="n">poscar</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="s2">&quot;POSCAR*&quot;</span><span class="p">))</span>
            <span class="n">terminal</span> <span class="o">=</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">i</span> <span class="o">==</span> <span class="n">neb_dirs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">terminal</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">ds</span> <span class="ow">in</span> <span class="n">terminal_dirs</span><span class="p">:</span>
                    <span class="n">od</span> <span class="o">=</span> <span class="n">ds</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">ds</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                    <span class="n">outcar</span> <span class="o">=</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">od</span><span class="p">,</span> <span class="s2">&quot;OUTCAR*&quot;</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">outcar</span><span class="p">:</span>
                        <span class="n">outcar</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">outcar</span><span class="p">)</span>
                        <span class="n">outcars</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Outcar</span><span class="p">(</span><span class="n">outcar</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
                        <span class="k">break</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;OUTCAR cannot be found for terminal &quot;</span>
                                     <span class="s2">&quot;point </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">d</span><span class="p">)</span>
                <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Poscar</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">poscar</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">outcars</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Outcar</span><span class="p">(</span><span class="n">outcar</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
                <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Poscar</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">contcar</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">NEBAnalysis</span><span class="o">.</span><span class="n">from_outcars</span><span class="p">(</span><span class="n">outcars</span><span class="p">,</span> <span class="n">structures</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>

<div class="viewcode-block" id="NEBAnalysis.as_dict"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.NEBAnalysis.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Dict representation of NEBAnalysis.</span>

<span class="sd">        Returns:</span>
<span class="sd">            JSON serializable dict representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
                <span class="s1">&#39;r&#39;</span><span class="p">:</span> <span class="n">jsanitize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">r</span><span class="p">),</span>
                <span class="s1">&#39;energies&#39;</span><span class="p">:</span> <span class="n">jsanitize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">),</span>
                <span class="s1">&#39;forces&#39;</span><span class="p">:</span> <span class="n">jsanitize</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">forces</span><span class="p">),</span>
                <span class="s1">&#39;structures&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structures</span><span class="p">]}</span></div></div>


<div class="viewcode-block" id="combine_neb_plots"><a class="viewcode-back" href="../../../pymatgen.analysis.transition_state.html#pymatgen.analysis.transition_state.combine_neb_plots">[docs]</a><span class="k">def</span> <span class="nf">combine_neb_plots</span><span class="p">(</span><span class="n">neb_analyses</span><span class="p">,</span> <span class="n">arranged_neb_analyses</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                      <span class="n">reverse_plot</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    neb_analyses: a list of NEBAnalysis objects</span>

<span class="sd">    arranged_neb_analyses: The code connects two end points with the</span>
<span class="sd">    smallest-energy difference. If all end points have very close energies, it&#39;s</span>
<span class="sd">    likely to result in an inaccurate connection. Manually arrange neb_analyses</span>
<span class="sd">    if the combined plot is not as expected compared with all individual plots.</span>
<span class="sd">    E.g., if there are two NEBAnalysis objects to combine, arrange in such a</span>
<span class="sd">    way that the end-point energy of the first NEBAnalysis object is the</span>
<span class="sd">    start-point energy of the second NEBAnalysis object.</span>
<span class="sd">    Note that the barrier labeled in y-axis in the combined plot might be</span>
<span class="sd">    different from that in the individual plot due to the reference energy used.</span>
<span class="sd">    reverse_plot: reverse the plot or percolation direction.</span>
<span class="sd">    return: a NEBAnalysis object</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">StructureMatcher</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">neb_index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">neb_analyses</span><span class="p">)):</span>
        <span class="k">if</span> <span class="n">neb_index</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">neb1</span> <span class="o">=</span> <span class="n">neb_analyses</span><span class="p">[</span><span class="n">neb_index</span><span class="p">]</span>
            <span class="n">neb1_energies</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1</span><span class="o">.</span><span class="n">energies</span><span class="p">)</span>
            <span class="n">neb1_structures</span> <span class="o">=</span> <span class="n">neb1</span><span class="o">.</span><span class="n">structures</span>
            <span class="n">neb1_forces</span> <span class="o">=</span> <span class="n">neb1</span><span class="o">.</span><span class="n">forces</span>
            <span class="n">neb1_r</span> <span class="o">=</span> <span class="n">neb1</span><span class="o">.</span><span class="n">r</span>
            <span class="k">continue</span>

        <span class="n">neb2</span> <span class="o">=</span> <span class="n">neb_analyses</span><span class="p">[</span><span class="n">neb_index</span><span class="p">]</span>
        <span class="n">neb2_energies</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">energies</span><span class="p">)</span>

        <span class="n">matching</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">neb1_s</span> <span class="ow">in</span> <span class="p">[</span><span class="n">neb1_structures</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">neb1_structures</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]:</span>
            <span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">neb1_s</span><span class="p">,</span> <span class="n">neb2</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="ow">or</span> \
                    <span class="n">x</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">neb1_s</span><span class="p">,</span> <span class="n">neb2</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
                <span class="n">matching</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="k">break</span>
        <span class="k">if</span> <span class="n">matching</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;no matched structures for connection!&quot;</span><span class="p">)</span>

        <span class="n">neb1_start_e</span><span class="p">,</span> <span class="n">neb1_end_e</span> <span class="o">=</span> <span class="n">neb1_energies</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">neb1_energies</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">neb2_start_e</span><span class="p">,</span> <span class="n">neb2_end_e</span> <span class="o">=</span> <span class="n">neb2_energies</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">neb2_energies</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">min_e_diff</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(([</span><span class="nb">abs</span><span class="p">(</span><span class="n">neb1_start_e</span> <span class="o">-</span> <span class="n">neb2_start_e</span><span class="p">),</span>
                           <span class="nb">abs</span><span class="p">(</span><span class="n">neb1_start_e</span> <span class="o">-</span> <span class="n">neb2_end_e</span><span class="p">),</span>
                           <span class="nb">abs</span><span class="p">(</span><span class="n">neb1_end_e</span> <span class="o">-</span> <span class="n">neb2_start_e</span><span class="p">),</span>
                           <span class="nb">abs</span><span class="p">(</span><span class="n">neb1_end_e</span> <span class="o">-</span> <span class="n">neb2_end_e</span><span class="p">)]))</span>

        <span class="k">if</span> <span class="n">arranged_neb_analyses</span><span class="p">:</span>
            <span class="n">neb1_energies</span> <span class="o">=</span> <span class="n">neb1_energies</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">neb1_energies</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> \
                            <span class="o">+</span> <span class="p">[(</span><span class="n">neb1_energies</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">neb2_energies</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="mi">2</span><span class="p">]</span> \
                            <span class="o">+</span> <span class="n">neb2_energies</span><span class="p">[</span>
                              <span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_structures</span> <span class="o">=</span> <span class="n">neb1_structures</span> <span class="o">+</span> <span class="n">neb2</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_forces</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_forces</span><span class="p">)</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">forces</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_r</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)</span> <span class="o">+</span> <span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="n">neb1_r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span>
                                     <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]]</span>

        <span class="k">elif</span> <span class="nb">abs</span><span class="p">(</span><span class="n">neb1_start_e</span> <span class="o">-</span> <span class="n">neb2_start_e</span><span class="p">)</span> <span class="o">==</span> <span class="n">min_e_diff</span><span class="p">:</span>
            <span class="n">neb1_energies</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">neb1_energies</span><span class="p">[</span><span class="mi">1</span><span class="p">:]))</span> <span class="o">+</span> <span class="n">neb2_energies</span>
            <span class="n">neb1_structures</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span>
                <span class="nb">reversed</span><span class="p">((</span><span class="n">neb1_structures</span><span class="p">[</span><span class="mi">1</span><span class="p">:])))</span> <span class="o">+</span> <span class="n">neb2</span><span class="o">.</span><span class="n">structures</span>
            <span class="n">neb1_forces</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">neb1_forces</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]))</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span>
                <span class="n">neb2</span><span class="o">.</span><span class="n">forces</span><span class="p">)</span>
            <span class="n">neb1_r</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span>
                <span class="p">[</span><span class="n">i</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="o">-</span> <span class="n">neb1_r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]]))</span> <span class="o">+</span> <span class="p">[</span>
                         <span class="n">i</span> <span class="o">+</span> <span class="n">neb1_r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)]</span>

        <span class="k">elif</span> <span class="nb">abs</span><span class="p">(</span><span class="n">neb1_start_e</span> <span class="o">-</span> <span class="n">neb2_end_e</span><span class="p">)</span> <span class="o">==</span> <span class="n">min_e_diff</span><span class="p">:</span>
            <span class="n">neb1_energies</span> <span class="o">=</span> <span class="n">neb2_energies</span> <span class="o">+</span> <span class="n">neb1_energies</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_structures</span> <span class="o">=</span> <span class="n">neb2</span><span class="o">.</span><span class="n">structures</span> <span class="o">+</span> <span class="n">neb1_structures</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_forces</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">forces</span><span class="p">)</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_forces</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_r</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)]</span> <span class="o">+</span> \
                     <span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]]</span>

        <span class="k">elif</span> <span class="nb">abs</span><span class="p">(</span><span class="n">neb1_end_e</span> <span class="o">-</span> <span class="n">neb2_start_e</span><span class="p">)</span> <span class="o">==</span> <span class="n">min_e_diff</span><span class="p">:</span>
            <span class="n">neb1_energies</span> <span class="o">=</span> <span class="n">neb1_energies</span> <span class="o">+</span> <span class="n">neb2_energies</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_structures</span> <span class="o">=</span> <span class="n">neb1_structures</span> <span class="o">+</span> <span class="n">neb2</span><span class="o">.</span><span class="n">structures</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_forces</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_forces</span><span class="p">)</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">forces</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_r</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)]</span> <span class="o">+</span> <span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="n">neb1_r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]]</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">neb1_energies</span> <span class="o">=</span> <span class="n">neb1_energies</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">neb2_energies</span><span class="p">))[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_structures</span> <span class="o">=</span> <span class="n">neb1_structures</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span>
                <span class="nb">reversed</span><span class="p">((</span><span class="n">neb2</span><span class="o">.</span><span class="n">structures</span><span class="p">)))[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_forces</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_forces</span><span class="p">)</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">forces</span><span class="p">)))[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">neb1_r</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span>
                <span class="nb">reversed</span><span class="p">([</span><span class="n">i</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="o">-</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                          <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb2</span><span class="o">.</span><span class="n">r</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]]))</span>

    <span class="k">if</span> <span class="n">reverse_plot</span><span class="p">:</span>
        <span class="n">na</span> <span class="o">=</span> <span class="n">NEBAnalysis</span><span class="p">(</span>
            <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">([</span><span class="n">i</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="o">-</span> <span class="n">neb1_r</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="o">-</span><span class="mi">1</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">)])),</span>
            <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">neb1_energies</span><span class="p">)),</span>
            <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">neb1_forces</span><span class="p">)),</span> <span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">neb1_structures</span><span class="p">)))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">na</span> <span class="o">=</span> <span class="n">NEBAnalysis</span><span class="p">(</span><span class="n">neb1_r</span><span class="p">,</span> <span class="n">neb1_energies</span><span class="p">,</span> <span class="n">neb1_forces</span><span class="p">,</span> <span class="n">neb1_structures</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">na</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.transition_state</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>